/*
 * SimpleButton.h
 *
 *  Created on: 2010-9-13
 *      Author: try
 */

#ifndef SIMPLEBUTTON_H_
#define SIMPLEBUTTON_H_

#include "../../commons.h"
#include "../../gdiplus/gdraw.h"
using namespace Ed;
namespace S {
  class SimpleButton: public Ed::Element {
    public:
      SimpleButton(const wchar_t* iconfilename, real x, real y) :
        isHovering(false) {
        pen = new Gdiplus::Pen(Gdiplus::Color(0, 0, 0));
        buttonImage = new Gdiplus::Bitmap(iconfilename);

        setCoordinate(x, y);
        setWidth(25);
        setHeight(25);
        createBoundRect();
      }
      virtual ~SimpleButton() {
        delete buttonImage;
        delete pen;
      }

      /**
       * 画此元素
       */
      void draw(Gdiplus::Graphics* g) {
        g->DrawImage(buttonImage, x(), y(), 24.0, 24.0);
        if (isHovering) {
          g->DrawRectangle(pen, x(), y(), width()-1, height()-1);
        }
        setModified(false);
        setRedraw(false);
      }

    protected:
      /**
       * 当鼠标在按钮上移动时
       */
      void mouseMoveEvent(const MouseEvent* e) {
        if (!isHovering) {
          isHovering = true;
          setModified(true);
        }
        //cout<<"SimpleButton.mouseMoveEvent"<<endl;
      }
      /**
       * 当鼠标在按钮上移出时
       */
      void mouseLeaveEvent(const MouseEvent* e) {
        isHovering = false;
        setModified(true);
        //cout<<"SimpleButton.mouseLeaveEvent"<<endl;
      }

      /**
       * 当鼠标在元素上按下按键时
       */
      void mousePressEvent(const MouseEvent* e) {
//        cout<<"SimpleButton.mousePressEvent"<<endl;
      }

    private:
      Gdiplus::Bitmap* buttonImage;
      //指示是否鼠标正悬停在元素上
      bool isHovering;
      Gdiplus::Pen* pen;
  };
}
#endif /* SIMPLEBUTTON_H_ */
